#region Using directives
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using webapp4U.BOL;
#endregion


namespace webapp4U.DAL
{
	 public class LanguagesDAL : BaseDAL
	 {
	     #region ObjIDataReader

	     /// <summary>
	     /// Returns a new Chatlieu instance filled with the DataReader's current record data 
	     /// </summary>
	     private Languages GetLanguagesFromReader(IDataReader dr)
	     {
		     Languages obj = new Languages();
             obj.LanguageID = (dr["LanguageID"] is DBNull) ? Int32.MinValue : (Int32)dr["LanguageID"];
             obj.LanguageCode = (dr["LanguageCode"] is DBNull) ? String.Empty : (String)dr["LanguageCode"];
             obj.LanguageName = (dr["LanguageName"] is DBNull) ? String.Empty : (String)dr["LanguageName"];
		     return obj;
	     }
	     #endregion

	     /// <summary>
	     /// Returns a collection of Chatlieu with the data read from the input DataReader
	     /// </summary>
	     private List<Languages> GetLanguagesCollectionFromReader(IDataReader dr)
	     {
		     List<Languages> obj = new List<Languages>();
		     while(dr.Read())
			     obj.Add(GetLanguagesFromReader(dr));
		     return obj;
	     }

	     
	     //Get All Chatlieu
	     public List<Languages> GetAllLanguages(int PageIndex, int PageSize)
	     {
		     using (SqlConnection myConn = GetConnectionString())
		     {
                 SqlCommand myCommand = new SqlCommand("w4u_Languages_GetAllLanguages", myConn); 
		     myCommand.CommandType = CommandType.StoredProcedure; 
		     myCommand.Parameters.Add("@PageIndex", SqlDbType.Int).Value = PageIndex;
		     myCommand.Parameters.Add("@PageSize", SqlDbType.Int).Value = PageSize;
		     SqlDataReader dr = myCommand.ExecuteReader();
		     return GetLanguagesCollectionFromReader(dr);
		     }
	     }

	     // Get Count All records of Table  Chatlieu
	     public int GetCountLanguages()
	     {
		     using (SqlConnection myConn = GetConnectionString())
		     {
                 SqlCommand myCommand = new SqlCommand("w4u_Languages_GetCountLanguages", myConn); 
		     myCommand.CommandType = CommandType.StoredProcedure; 
		     return (int)myCommand.ExecuteScalar();
		     }
	     }



	 }
}
